define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {


    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'invoice/index' + location.search,
                     edit_url: 'invoice/edit',
                    multi_url: 'invoice/multi',
        
                    table: 'invoice',
                }
            });
        
            var types = $("#types").val();
        
            var table = $("#table");
            if(types == 0){
                    // 初始化表格
                table.bootstrapTable({
                    url: $.fn.bootstrapTable.defaults.extend.index_url,
                    pk: 'id',
                    sortName: 'id',
                    fixedColumns: true,
                    fixedRightNumber: 1,
                    columns: [
                        [
                            {checkbox: true},
                            {field: 'id', title: __('Id')},
                            {field: 'umobile', title: __('Umobile'), operate: 'LIKE'},
                            {field: 'top_type', title: __('抬头类型'), searchList: {"0":__('增值税普通发票'),"1":__('增值税专用发票')}, formatter: Table.api.formatter.normal},
                            {field: 'top_title', title: __('Top_title'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                            {field: 'ic_type', title: __('发票类型'), searchList: {"0":__('电子发票'),"1":__('纸质发票')}, formatter: Table.api.formatter.normal},
                            {field: 'money', title: __('发票金额'), operate:'BETWEEN'},
                            {field: 'ems', title: __('Ems'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                            {field: 'address', title: __('Address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                            
                            {field: 'status', title: __('订单状态'), searchList: {"0":__('申请中'),"1":__('处理成功'),"2":__('处理失败'),"3":__('申请退单中'),"4":__('申请退单通过'),"5":__('拒绝申请退单')}, formatter: Table.api.formatter.status},
                            {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                            {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                        ]
                    ]
                });
            }else if(types==2){
                table.bootstrapTable({
                    url: $.fn.bootstrapTable.defaults.extend.index_url,
                    pk: 'id',
                    sortName: 'id',
                    fixedColumns: true,
                    fixedRightNumber: 1,
                    columns: [
                        [
                            {checkbox: true},
                            {field: 'id', title: __('Id')},
                            {field: 'umobile', title: __('Umobile'), operate: 'LIKE'},
                            {field: 'top_type', title: __('抬头类型'), searchList: {"0":__('增值税普通发票'),"1":__('增值税专用发票')}, formatter: Table.api.formatter.normal},
                            {field: 'top_title', title: __('Top_title'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                            {field: 'ic_type', title: __('发票类型'), searchList: {"0":__('电子发票'),"1":__('纸质发票')}, formatter: Table.api.formatter.normal},
                            {field: 'money', title: __('发票金额'), operate:'BETWEEN'},
                            {field: 'ems', title: __('Ems'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                            {field: 'address', title: __('Address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                          
                            {field: 'zz_taxpayer', title: __('Zz_taxpayer'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                            {field: 'status', title: __('订单状态'), searchList: {"0":__('申请中'),"1":__('处理成功'),"2":__('处理失败')}, formatter: Table.api.formatter.status},
                            {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                            {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                        ]
                    ]
                });
            }else{
                 // 初始化表格
                 table.bootstrapTable({
                    url: $.fn.bootstrapTable.defaults.extend.index_url,
                    pk: 'id',
                    sortName: 'id',
                    fixedColumns: true,
                    fixedRightNumber: 1,
                    columns: [
                        [
                            {checkbox: true},
                            {field: 'id', title: __('Id')},
                              {field: 'umobile', title: __('Umobile'), operate: 'LIKE'},
                            {field: 'type', title: __('Type'), searchList: {"0":__('个人'),"1":__('企业'),"2":__('组织')}, formatter: Table.api.formatter.normal},
                            {field: 'top_type', title: __('抬头类型'), searchList: {"0":__('增值税普通发票'),"1":__('增值税专用发票')}, formatter: Table.api.formatter.normal},
                            {field: 'top_title', title: __('Top_title'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                            {field: 'ic_type', title: __('发票类型'), searchList: {"0":__('电子发票'),"1":__('纸质发票')}, formatter: Table.api.formatter.normal},
                            {field: 'money', title: __('发票金额'), operate:'BETWEEN'},
                            {field: 'ems', title: __('Ems'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                            {field: 'address', title: __('Address'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                         
                            {field: 'qy_taxpayer', title: __('Qy_taxpayer'), operate: 'LIKE'},
                            {field: 'qy_khh', title: __('Qy_khh'), operate: 'LIKE'},
                            {field: 'qy_account', title: __('Qy_account'), operate: 'LIKE'},
                            {field: 'qy_address', title: __('Qy_address'), operate: 'LIKE'},
                            {field: 'qy_phone', title: __('Qy_phone'), operate: 'LIKE'},
                          
                            {field: 'status', title: __('订单状态'), searchList: {"0":__('申请中'),"1":__('处理成功'),"2":__('处理失败')}, formatter: Table.api.formatter.status},
                            {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                            {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                        ]
                    ]
                });
            }
            

           

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
